'''
Created on 2012-9-19

@author: infear
'''
def conflict(state,nextX):
    nextY=len(state)
    for i in range(nextY):
        if nextX==state[i] or abs(nextX-state[i])==nextY-i:
            return True
    return False

def queens(num,state):
    if len(state)==num-1:
        for i in range(num):
            if not conflict(state, i):
                yield i
                
def solution(num=8,state=()):
    for i in range(num):
        if not conflict(state, i):
            if len(state)==num-1:
                yield (i,)
            else:
                for result in solution(num, state+(i,)):
                    yield (i,)+result
                
print list(queens(4,[1,3,0])) 
print list(solution())    